package com.study.patterns.proxy.dynamic.asm.base;

import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;

/**
 * Created by tan on 2017/6/22.
 */
public class SetMethodAdapter extends MethodVisitor {
	public SetMethodAdapter(int api, MethodVisitor mv) {
		super(api, mv);
	}

	@Override
	public void visitCode() {
		mv.visitVarInsn(Opcodes.ALOAD, 0);
		mv.visitVarInsn(Opcodes.ALOAD, 1);
		//设置name属性值
		mv.visitFieldInsn(Opcodes.PUTFIELD, "com/study/patterns/proxy/dynamic/asm/base/MyClass", "name", Type.getDescriptor(String.class));
		//设置返回值
		mv.visitInsn(Opcodes.RETURN);
		//设置方法栈和本地变量表的大小
		//TODO 这是怎么计算的
		mv.visitMaxs(2, 2);
	}
}
